package geez.widget;

import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;

import static geez.widget.Geez.withNameAndId;
import static geez.widget.Geez.withStyle;

public class GButton extends Button implements GClickable, GFocusable, GTextSetable {

    public GButton() {
    }

    public GButton(String html) {
        super(html);
    }

    @Deprecated
    public GButton(String html, ClickListener listener) {
        super(html, listener);
    }

    public GButton(String html, ClickHandler handler) {
        super(html, handler);
    }

    public GButton id(String id) {
        withNameAndId(this, id);
        return this;
    }

    public GButton css(String cssClass, String... optionalClasses) {
        withStyle(this, cssClass, optionalClasses);
        return this;
    }

    public GButton pixelSize(int width, int height) {
        setPixelSize(width, height);
        return this;
    }

    public GButton tabIndex(int index) {
        setTabIndex(index);
        return this;
    }

    public GButton add(ClickHandler handler) {
        addClickHandler(handler);
        return this;
    }

    @Deprecated
    public GButton add(ClickListener listener) {
        addClickListener(listener);
        return this;
    }

    public GButton text(String text) {
        setText(text);
        return this;
    }

    public GButton enable() {
        setEnabled(true);
        return this;
    }

    public GButton disable() {
        setEnabled(false);
        return this;
    }

    public GButton show() {
        setVisible(true);
        return this;
    }

    public GButton hide() {
        setVisible(false);
        return this;
    }

    public GButton add(FocusHandler handler) {
        addFocusHandler(handler);
        return this;
    }

    public GButton add(BlurHandler handler) {
        addBlurHandler(handler);
        return this;
    }

    public GButton focus() {
        setFocus(true);
        return this;
    }
}
